<template>
  <div style="text-align: center">
    <el-form ref="form" :model="form" :rules="rules" label-width="80px">

        <div style="display: flex">
          <div style="flex: 1">

            <el-form-item label="原手牌号" prop="handBrand">
              <el-input v-model="form.handBrand" placeholder="请输入原手牌号"/>
            </el-form-item>
            <el-form-item label="新手牌号" prop="note5">
              <el-input v-model="form.note5" placeholder="请输入新手牌号"/>
            </el-form-item>

          </div>
        </div>

    </el-form>



    <div slot="footer" class="dialog-footer"  style="text-align: right;">
      <el-button type="primary" @click="huan">换牌</el-button>
      <el-button @click="cancel">返 回</el-button>
    </div>
  </div>
</template>

<script>
import { listHands, getHands, delHands, addHands, updateHands ,huanpai,checkhuanpai} from "@/api/module/wyw/hands";
export default {
  name: "huanpai",
  props: ['huanpaihandid'], // 接收传入的 id
  dicts: ['yqg_locked_state'],
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 手牌基础信息表格数据
      handsList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        handBrand: null,
        handCategory: null,
        handState: null,
        lockedState: null,
        note1: null,
        note2: null,
        note3: null,
        note4: null,
        note5: null
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {

        handBrand: [
          { required: true, message: "原手牌号不能为空", trigger: "blur" },
        ],
        note5: [
          { required: true, message: "新手牌号不能为空", trigger: "blur" },
        ],


      }
    };
  },
 /* watch: {
    huanpaihandid() {
      // 当 id 值发生改变时，重新获取或者刷新数据
      this.form.handBrand=this.huanpaihandid[0];
      this.getList();
    },
  },*/
  created() {
  /*  if(this.huanpaihandid){
      this.form.handBrand=this.huanpaihandid[0];
    }
    this.getList();*/
  },
  methods: {
// 表单重置
    reset() {
      this.form = {
        id: null,
        handBrand: null,
        handCategory: null,
        handState: null,
        lockedState: null,
        note1: null,
        note2: null,
        note3: null,
        note4: null,
        note5: null
      };
      this.resetForm("form");
    },

    /** 查询手牌基础信息列表 */
    getList() {
      this.loading = true;
      listHands(this.form).then(response => {
        this.handsList = response.rows;
      });
    },


    huan(){
   /*   this.$refs["form"].validate(valid => {


        this.$modal.confirm('是否确认换牌？').then(function () {
        }).then(() => {
          huanpai(this.form);
          this.$modal.msgSuccess("换牌成功");
          this.$emit("closeDialog"); // 触发 closeDialog 事件
          this.reset();
        }).catch(() => {
        });
      })*/



      this.$refs["form"].validate(valid => {
        if (valid) {
          this.$refs["form"].validate(valid => {

            checkhuanpai(this.form).then(response => {
              this.$modal.confirm('是否确认换牌？').then(function () {
              }).then(() => {
                huanpai(this.form);
                this.$modal.msgSuccess("换牌成功");

                //this.reset();
              }).catch(() => {
              });
            });

          })
        }
      });
    },
    cancel(){
      this.$emit("closeDialog"); // 触发 closeDialog 事件
      this.reset();
    }
  }


}

</script>

<style scoped>

</style>
